<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>${_title}</title>

    <!-- Bootstrap core CSS -->

    <link href="${_css}/bootstrap.min.css" rel="stylesheet">

    <link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
    <link href="${_css}/animate.min.css" rel="stylesheet">

    <link href="${_css}/custom.css" rel="stylesheet">
	
	<link rel="stylesheet" href="${_css}/jquery-ui-1.10.4.custom.min.css"/>
	
	<!-- ztree -->
	<link rel="stylesheet" href="${_js}/ztree/css/zTreeStyle.css"/>
	
    <script src="${_js}/jquery.min.js"></script>
	
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->

</head>

<body style="background: #F7F7F7;">
<div class="" style="height:1000px;">
	<form class="form-horizontal form-label-left" novalidate>
		<input type="hidden" id="groupId" value="<#if groupId?exists>${groupId}</#if>"></hidden>
	</form>
	<div class="row">
		<div class="col-md-12 col-sm-12 col-xs-12">
			<ul id="menuTree" class="ztree"></ul>
		</div>	
	</div>
	<div class="row">
		<div class="col-md-12 col-sm-12 col-xs-12">
		    <div class="ln_solid"></div>
		    <div class="form-group">
		        <div class="col-md-12 col-md-offset-5">
		            <button type="button" onclick="javascript:history.go(-1)" class="btn btn-primary">返回前一页</button>
		            <button id="send" type="button" class="btn btn-success">保存</button>
		        </div>
		    </div>			
		</div>
	</div> 
</div>
	<script type="text/javascript">
		var setting = {
	        view: {
	            showIcon: false
	        },
	        check: {
	            enable: true
	        },
	        data: {
	            simpleData: {
	                enable: true
	            }
	        }
	    };
		
		function setCheck() {
			var zTree = $.fn.zTree.getZTreeObj("menuTree"),
			py = $("#py").attr("checked")? "p":"",
			sy = $("#sy").attr("checked")? "s":"",
			pn = $("#pn").attr("checked")? "p":"",
			sn = $("#sn").attr("checked")? "s":"",
			type = { "Y":py + sy, "N":pn + sn};
			zTree.setting.check.chkboxType = type;
			showCode('setting.check.chkboxType = { "Y" : "' + type.Y + '", "N" : "' + type.N + '" };');
		}
		function showCode(str) {
			if (!code) code = $("#code");
			code.empty();
			code.append("<li>"+str+"</li>");
		}
		
		$(document).ready(function(){
			var groupId = $("#groupId").val();
			$.ajax({
	            type: 'POST',
	            dataType: 'JSON',
	            async:'false',
	            headers: {'Content-type': 'application/json;charset=UTF-8'},
	            url: '/admin/group/data?groupId='+groupId,
	            success: function(result){
	  				$.fn.zTree.init($("#menuTree"), setting, result);
	            }
		    });
	    });
	    
		$(".btn-success").click(function(){
			var ztree = $.fn.zTree.getZTreeObj("menuTree");
	        var nodes = ztree.getCheckedNodes(true);
	        var checked = [];
	        var groupId = $("#groupId").val();
	        for (var i = 0; i < nodes.length; i++) {
	        	var data ={"groupId":groupId,"menuId":nodes[i].id};  
	            checked.push(data);
	        }
        
	        $.ajax({
	            type: 'post',
	            dataType: 'json',
	            headers: {'Content-type': 'application/json;charset=UTF-8'},
	            url: '/admin/group/saveGroupMenu',
	            data: JSON.stringify(checked),
	            success: function(result){
            		if(result.code==-1){
	            		new PNotify({
			            	title: '操作提示',
			            	text: '保存成功',
			            	delay: 3e3,
			            	type: 'success'
			        	});
			        	window.location.reload();	   
				  }else{
						new PNotify({
				        	title: '操作提示',
				        	text: result.msg,
				        	delay: 3e3,
				        	type: 'error'
				    	});       		  	
				  }
	            }
	        });
		});
	</script>	
    <script src="${_js}/bootstrap.min.js"></script>
    <!-- bootstrap progress js -->
	<script src="${_js}/progressbar/bootstrap-progressbar.min.js" type="text/javascript"></script>
	<script src="${_js}/nicescroll/jquery.nicescroll.min.js" type="text/javascript"></script>
    
	<script src="${_js}/custom.js" type="text/javascript"></script>
            
	 <!-- PNotify -->
	<script src="${_js}/notify/pnotify.core.js" type="text/javascript"></script>
	<script src="${_js}/notify/pnotify.buttons.js" type="text/javascript"></script>
	<script src="${_js}/notify/pnotify.nonblock.js" type="text/javascript" ></script>   
	
	<!-- Ztree -->
	<script src="${_js}/ztree/js/jquery.ztree.core-3.5.js" type="text/javascript"></script>
	<script src="${_js}/ztree/js/jquery.ztree.excheck-3.5.min.js" type="text/javascript"></script>
</body>

</html>